<html>
<head>
	<title>Mighty Editor - reset password</title>
	<meta charset="UTF-8" >
	<link rel="stylesheet" type="text/css" href="css/main.css" />
	<link rel="icon" href="favicon.ico" type="image/x-icon" />
	<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
	<style>
	body > .ui-mysettings.standAlone{
		width: 330px;
	}
	#mainblock:before{
		content: "new password"
	}
	.ui-mysettings.standAlone .ui-button.register{
		margin: 0;
		padding: 0;
	}
	</style>
	<script type="text/javascript" src="js/eClass.js"></script>
</head>
<body>
<div class="ui-mysettings standAlone"><div class="signup" id="mainblock"><div class="login logo"></div><div class="ui-button register"></div></div></div>
<script>
window.MT = createClass("MT");
MT.require("ui.Input");
MT.require("ui.Controller");
MT.require("misc.validation");
MT.require("core.Helper");

MT.onReady(function(){
	var kip, pass;
	
	
	var par = document.getElementById("mainblock");
	var form = document.createElement("form");
	form.setAttribute("action", "/resetpassword/");
	form.setAttribute("method", "post");
	form.onsubmit = function(e){
		e.preventDefault();
		e.stopPropagation();
	};
	var input = {};
	var prop = {
		password: "password",
		passwordR: "passwordR"
	};
	
	
	var key = window.location.toString().split("?").pop();
	
	
	var isValid = MT.misc.validation;
	var submit = function(){
		if(isValid.password(input.password.getValue())){
			input.password.value.removeClass("error");
		}
		else{
			input.password.value.addClass("error");
			input.password.value.el.setAttribute("data-error", "at least one number and at least six characters");
			return;
		}
		
		if(input.password.getValue() == input.passwordR.getValue()){
			input.passwordR.value.removeClass("error");
		}
		else{
			input.passwordR.value.addClass("error");
			input.passwordR.value.el.setAttribute("data-error", "passwords don't match");
			return;
		}
		
		pass.value = MT.core.Helper.sha256(input.password.getValue());
		form.submit();
	};
	
	var ui = new MT.ui.Controller();
	input.password = new MT.ui.Input(ui, {key: "password", type: "password"}, prop);
	input.password.show(form);
	input.password.value.el.innerHTML = "New Password";
	input.password.value.el.name = "password";
	
	
	input.passwordR = new MT.ui.Input(ui, {key: "passwordR", type: "password"}, prop);
	input.passwordR.show(form);
	input.passwordR.value.el.innerHTML = "Repeat Password";
	input.passwordR.value.el.name = "passwordR";
	
	
	var loginButton = new MT.ui.Button("Change", "login.mainbutton", null, submit);
	loginButton.show(form);
	
	
	if(key != ""){
		kip = document.createElement("input");
		kip.setAttribute("type", "hidden");
		kip.value = key;
		kip.name = "key";
		form.appendChild(kip);
		
		pass = document.createElement("input");
		pass.setAttribute("type", "hidden");
		pass.name = "password";
		
		form.appendChild(pass);
		
		par.appendChild(form);
	}
	
	
});
</script>
</body>
<html>
